﻿#region File and License Information
/*
<File>
	<License>
		Copyright © 2009 - 2017, Daniel Vaughan. All rights reserved.
		This file is part of Calcium (http://calciumsdk.net), 
		which is released under the MIT License.
		See file /Documentation/License.txt for details.
	</License>
	<CreationDate>2011-11-21 14:25:04Z</CreationDate>
</File>
*/
#endregion

using System.Collections.Generic;

namespace Outcoder.Linq
{
	/* TODO: [DV] Comment. */
	public class Pair<T1, T2>
	{
		public Pair()
		{
		}

		public Pair(T1 first, T2 second)
		{
			this.First = first;
			this.Second = second;
		}

		public T1 First { get; set; }
		public T2 Second { get; set; }

		public override bool Equals(object obj)
		{
			if (ReferenceEquals(null, obj))
			{
				return false;
			}
			if (ReferenceEquals(this, obj))
			{
				return true;
			}
			if (obj.GetType() != typeof(Pair<T1, T2>))
			{
				return false;
			}
			return Equals((Pair<T1, T2>)obj);
		}

		public bool Equals(Pair<T1, T2> other)
		{
			if (ReferenceEquals(null, other))
			{
				return false;
			}
			if (ReferenceEquals(this, other))
			{
				return true;
			}
			return Equals(other.First, First) && Equals(other.Second, Second);
		}

		public override int GetHashCode()
		{
			unchecked
			{
				return (First.GetHashCode() * 397) ^ Second.GetHashCode();
			}
		}

		public class EqualityComparer : IEqualityComparer<Pair<T1, T2>>
		{
			public bool Equals(Pair<T1, T2> x, Pair<T1, T2> y)
			{
				if (object.Equals(x, y))
				{
					return true;
				}
				if (object.Equals(x, null))
				{
					return false;
				}
				return x.Equals(y);
			}

			public int GetHashCode(Pair<T1, T2> obj)
			{
				return obj.GetHashCode();
			}
		}
	}
}